/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.service.battle.coreBattleLogic.singleCardType;

import com.dc.gameserver.baseConfig.Config;
import com.dc.gameserver.hardCode.CardType;
import com.dc.gameserver.serverCore.service.battle.GameFormula;
import com.dc.gameserver.serverCore.service.battle.coreBattleLogic.AbstractSingleLogic;
import com.dc.gameserver.serverCore.service.cardModule.CardBox;
import com.dc.gameserver.serverCore.service.cardModule.CardBoxManager;
import com.dc.gameserver.serverCore.service.character.GameCharacter;
import org.springframework.stereotype.Service;

/**
 * @author 石头哥哥</br>
 *         Project : gameServer1.1</br>
 *         Date: 13-11-2  11</br>
 *         Time: 下午11:02</br>
 *         Connect: 13638363871@163.com</br>
 *         packageName: Server.ServerCore.Service.fightProcess.singleCardType</br>
 *         注解：
 */
@Service
public class singleAttackLogic extends AbstractSingleLogic {

    @Override
    public void PostConstruct() {
        SINGLES[CardType.ATTACK_TYPE.getType()]=this;
    }



    /**
     * 处理不同类型牌的逻辑
     * @param p1   出牌对象  ，p1 使用攻击牌类型
     * @param p2   没有出牌的玩家
     */
    @Override
    public void SingleLogicHandle(GameCharacter p1,GameCharacter p2) {
        CardBox cardBox= CardBoxManager.getCardBoxByID(p1.getCardBoxID());

        //判定玩家相克性      p1--->p2
        //1 .相克  a-->b ; 2.不相克 a---b; 3.被克 a<---b;
        // p1 攻方，p2.防守方
        int garms= GameFormula.grams(p1.getSelfFiveType(), p2.getSelfFiveType());
        int p2Hurt=0;  //p2 造成的伤害
//        int p2Blood=p2.getCurrentBlood();
        int p2Shield=p2.getCurrentShield();
        int p2Defence=p2.getDefence();
        int p1Attack=p1.getAttack();
        if (garms== 0x1){
            p2Hurt=GameFormula.attackHurtWithGrams(p2Defence, p1Attack);
        }else if (garms== 0x2){
            p2Hurt=GameFormula.attackHurtWithUnGrams(p2Defence, p1Attack);
        } else {
            p2Hurt=GameFormula.attackHurtWithGramsed(p2Defence, p1Attack);
        }
        if (p2Hurt<=0){
            p2Hurt=0;
            p2Hurt= Config.DEFAULT_VALUE.GAME_VALUE.hurt;
        }

        //p1对p2进行物理攻击
//        if (p2Shield>p2Hurt){
//            p2.setCurrentShield(p2Shield-p2Hurt);
//        } else {
//            if (p2Shield==0){
//                p2.setCurrentBlood(p2Blood-p2Hurt);
//            }else {
//                p2.setCurrentBlood(p2Blood+p2Shield-p2Hurt);
//                p2.setCurrentShield(0);  //next time will be 0
//            }
//        }
        p2.setCurrentShield(p2Shield-p2Hurt);
        cardBox.sendHurtRule(p2.getID(),p2Hurt,p1.getBattleSkillID());
        if (p2.getCurrentShield()<=0){
            p2.setCurrentShield(0);
            //被攻击掉血
            cardBox.flushBloodAndMagic();
            cardBox.notifyPkResult(p1);
            CardBoxManager.clearPkResourceWithRoundOver(cardBox.getCardBoxID());
        } else {
            cardBox.flushBloodAndMagic();
            cardBox.resetRoundResource();
        }

    }
}
